package server.servlets;


import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import commons.Manager;
import commons.User;
import server.filters.RestrictedPagesToConnectedUser;

/**
 * Servlet used to log out the user. It redirects him to the connection page.
 * @author Romain Pellerin
 */
public class Logout extends HttpServlet {

	private static final long serialVersionUID = -1159310879821597780L;

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		User user = RestrictedPagesToConnectedUser.getUserIfConnected(request);
		if (user != null) {
			Manager.getInstance().delUser(user);
		}
		HttpSession session = request.getSession();
		session.invalidate();
		response.sendRedirect("connection");
	}
}